﻿#region Header
// ------------------------ Licence / Copyright ------------------------
// 
// ScrumTable for Scrum Meeting Support
// Copyright © HSR - Hochschule für Technik Rapperswil
// All Rights Reserved
// 
// Author:
//  Michael Gfeller Silvan Gehrig Patrick Boos
// 
// ---------------------------------------------------------------------
#endregion

#region Usings

using System;
using ScrumTable.Common.Collections;
using ScrumTable.Common.Monitoring;
using ScrumTable.DL.Data.Generic;
using ScrumTable.DL.Data.Generic.Services;

#endregion

namespace ScrumTable.DL.Data.Excel.Services
{
    /// <summary>
    /// This class is used to load data into the current data driver.
    /// </summary>
    internal class DataLoader : IDataLoader
    {
        #region Declarations
        //--------------------------------------------------------------------
        // Declarations
        //--------------------------------------------------------------------

        #endregion

        #region Properties
        //--------------------------------------------------------------------
        // Properties
        //--------------------------------------------------------------------

        #endregion

        #region Constructors / Destructor
        //--------------------------------------------------------------------
        // Constructors / Destructor
        //--------------------------------------------------------------------

        /// <summary>
        /// Creates a new DataLoader instance, no public constructor
        /// needed.
        /// </summary>
        internal DataLoader()
        {
        }

        #endregion

        #region Methods
        //--------------------------------------------------------------------
        // Methods
        //--------------------------------------------------------------------

        /// <summary>
        /// Loads the data which is required to connect to the back end tfs
        /// system.
        /// </summary>
        /// <param name="dataContext">Specifies the data context which contains the underlying data driver root object.</param>
        /// <param name="callback">Specifies the callback used to retrieve the connection state. The callback value is of type DataResult.</param>
        public void LoadConnectionData(GenericDataContextBase dataContext, AsyncCallback callback)
        {
            new ConnectionCacheLoader(
                dataContext.Connection.ConnectionManager,
                dataContext.Connection.ConnectionMoniker,
                dataContext.Schema,
                callback,
                ((DataContext)dataContext).ConfigurationInternal.LoadAsync).LoadData();
        }

        /// <summary>
        /// Loads the data blow the given key chain.
        /// </summary>
        /// <param name="dataContext">Specifies the data context which contains the underlying data driver root object.</param>
        /// <param name="idChain">The data below the given id should be imported.</param>
        /// <param name="importMonitor">Specifies the monitor which observes the import.</param>
        public void LoadInitialData(GenericDataContextBase dataContext, ValueChain<string> idChain, IDataImportMonitor importMonitor)
        {
            new InitialDataCacheLoader(
                dataContext.DataCache,
                idChain,
                importMonitor).LoadData();
        }

        #endregion

        #region Events
        //--------------------------------------------------------------------
        // Events
        //--------------------------------------------------------------------

        #endregion
    }
}